package cn.zhaoyuening.zshop4j.manager.web;

import cn.zhaoyuening.zshop4j.common.bean.EasyUiTreeNode;
import cn.zhaoyuening.zshop4j.common.utils.JsonUtils;
import cn.zhaoyuening.zshop4j.manager.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Zhao on 2017/4/7.
 */
@Controller
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @RequestMapping(value = "itemCats",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String findByParentNodeId(@RequestParam(value = "id",defaultValue = "0") long id) {
        List<EasyUiTreeNode> easyUiTreeNodeList = itemCatService.findByParentId(id);
        String json = JsonUtils.objectToJson(easyUiTreeNodeList);
        return json;
    }
}
